<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LocalStorage 数据检查</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            background-color: #f5f5f5;
        }
        .container {
            max-width: 1200px;
            margin: 0 auto;
            background-color: white;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            text-align: center;
        }
        .section {
            margin-bottom: 30px;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        h2 {
            color: #555;
            border-bottom: 2px solid #007bff;
            padding-bottom: 10px;
        }
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 15px;
        }
        th, td {
            border: 1px solid #ddd;
            padding: 12px;
            text-align: left;
        }
        th {
            background-color: #007bff;
            color: white;
        }
        tr:nth-child(even) {
            background-color: #f2f2f2;
        }
        .status-pending {
            color: #ffc107;
            font-weight: bold;
        }
        .status-running {
            color: #17a2b8;
            font-weight: bold;
        }
        .status-completed {
            color: #28a745;
            font-weight: bold;
        }
        .status-failed {
            color: #dc3545;
            font-weight: bold;
        }
        .empty-message {
            text-align: center;
            color: #666;
            font-style: italic;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>LocalStorage 数据检查</h1>
        
        <div class="section">
            <h2>作业数据 (ai_platform_jobs)</h2>
            <div id="jobs-container">
                <p class="empty-message">加载中...</p>
            </div>
        </div>
        
        <div class="section">
            <h2>特征任务数据 (ai_platform_feature_tasks)</h2>
            <div id="feature-tasks-container">
                <p class="empty-message">加载中...</p>
            </div>
        </div>
        
        <div class="section">
            <h2>数据集 (ai_platform_datasets)</h2>
            <div id="datasets-container">
                <p class="empty-message">加载中...</p>
            </div>
        </div>
    </div>

    <script>
        // 显示作业数据
        function displayJobs() {
            const container = document.getElementById('jobs-container');
            try {
                const jobsData = localStorage.getItem('ai_platform_jobs');
                if (jobsData) {
                    const jobs = JSON.parse(jobsData);
                    if (jobs && jobs.length > 0) {
                        let html = `
                            <table>
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>名称</th>
                                        <th>类型</th>
                                        <th>状态</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                        `;
                        
                        jobs.forEach(job => {
                            // 根据状态设置CSS类
                            let statusClass = '';
                            switch (job.status) {
                                case 'pending':
                                    statusClass = 'status-pending';
                                    break;
                                case 'running':
                                    statusClass = 'status-running';
                                    break;
                                case 'completed':
                                    statusClass = 'status-completed';
                                    break;
                                case 'failed':
                                    statusClass = 'status-failed';
                                    break;
                                default:
                                    statusClass = '';
                            }
                            
                            html += `
                                <tr>
                                    <td>${job.id || 'N/A'}</td>
                                    <td>${job.name || 'N/A'}</td>
                                    <td>${job.type || 'N/A'}</td>
                                    <td class="${statusClass}">${job.status || 'N/A'}</td>
                                    <td>${job.createdAt ? new Date(job.createdAt).toLocaleString() : 'N/A'}</td>
                                </tr>
                            `;
                        });
                        
                        html += `
                                </tbody>
                            </table>
                        `;
                        
                        container.innerHTML = html;
                    } else {
                        container.innerHTML = '<p class="empty-message">没有找到作业数据</p>';
                    }
                } else {
                    container.innerHTML = '<p class="empty-message">LocalStorage 中没有作业数据</p>';
                }
            } catch (error) {
                container.innerHTML = `<p class="empty-message">解析作业数据时出错: ${error.message}</p>`;
            }
        }
        
        // 显示特征任务数据
        function displayFeatureTasks() {
            const container = document.getElementById('feature-tasks-container');
            try {
                const tasksData = localStorage.getItem('ai_platform_feature_tasks');
                if (tasksData) {
                    const tasks = JSON.parse(tasksData);
                    if (tasks && tasks.length > 0) {
                        let html = `
                            <table>
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>名称</th>
                                        <th>类型</th>
                                        <th>状态</th>
                                        <th>进度</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                        `;
                        
                        tasks.forEach(task => {
                            // 根据状态设置CSS类
                            let statusClass = '';
                            switch (task.status) {
                                case 'pending':
                                    statusClass = 'status-pending';
                                    break;
                                case 'running':
                                    statusClass = 'status-running';
                                    break;
                                case 'completed':
                                    statusClass = 'status-completed';
                                    break;
                                case 'failed':
                                    statusClass = 'status-failed';
                                    break;
                                default:
                                    statusClass = '';
                            }
                            
                            html += `
                                <tr>
                                    <td>${task.id || 'N/A'}</td>
                                    <td>${task.name || 'N/A'}</td>
                                    <td>${task.type || 'N/A'}</td>
                                    <td class="${statusClass}">${task.status || 'N/A'}</td>
                                    <td>${task.progress !== undefined ? task.progress + '%' : 'N/A'}</td>
                                    <td>${task.createdAt ? new Date(task.createdAt).toLocaleString() : 'N/A'}</td>
                                </tr>
                            `;
                        });
                        
                        html += `
                                </tbody>
                            </table>
                        `;
                        
                        container.innerHTML = html;
                    } else {
                        container.innerHTML = '<p class="empty-message">没有找到特征任务数据</p>';
                    }
                } else {
                    container.innerHTML = '<p class="empty-message">LocalStorage 中没有特征任务数据</p>';
                }
            } catch (error) {
                container.innerHTML = `<p class="empty-message">解析特征任务数据时出错: ${error.message}</p>`;
            }
        }
        
        // 显示数据集
        function displayDatasets() {
            const container = document.getElementById('datasets-container');
            try {
                const datasetsData = localStorage.getItem('ai_platform_datasets');
                if (datasetsData) {
                    const datasets = JSON.parse(datasetsData);
                    if (datasets && datasets.length > 0) {
                        let html = `
                            <table>
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>名称</th>
                                        <th>类型</th>
                                        <th>描述</th>
                                        <th>创建时间</th>
                                    </tr>
                                </thead>
                                <tbody>
                        `;
                        
                        datasets.forEach(dataset => {
                            html += `
                                <tr>
                                    <td>${dataset.id || 'N/A'}</td>
                                    <td>${dataset.name || 'N/A'}</td>
                                    <td>${dataset.type || 'N/A'}</td>
                                    <td>${dataset.description || 'N/A'}</td>
                                    <td>${dataset.uploadedAt ? new Date(dataset.uploadedAt).toLocaleString() : 'N/A'}</td>
                                </tr>
                            `;
                        });
                        
                        html += `
                                </tbody>
                            </table>
                        `;
                        
                        container.innerHTML = html;
                    } else {
                        container.innerHTML = '<p class="empty-message">没有找到数据集</p>';
                    }
                } else {
                    container.innerHTML = '<p class="empty-message">LocalStorage 中没有数据集</p>';
                }
            } catch (error) {
                container.innerHTML = `<p class="empty-message">解析数据集时出错: ${error.message}</p>`;
            }
        }
        
        // 页面加载完成后显示数据
        document.addEventListener('DOMContentLoaded', function() {
            displayJobs();
            displayFeatureTasks();
            displayDatasets();
        });
    </script>
</body>
</html>